home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Games Extra 1996 September
/
Amiga Games Extra CD-ROM 9-1996.iso
/
userbox
/
publicdomain
/
vim-4.2
/
src
/
digraph.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-06-09
|
14KB
|
552 lines
/* vi:set ts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
*/
/*
* digraph.c: code for digraphs
*/
#include "vim.h"
#include "globals.h"
#include "proto.h"
#include "option.h"
#ifdef DIGRAPHS
static int getexactdigraph __ARGS((int, int, int));
static void printdigraph __ARGS((char_u *));
static char_u (*digraphnew)[3]; /* pointer to added digraphs */
static int digraphcount = 0; /* number of added digraphs */
#if defined(MSDOS) || defined(WIN32) || defined(OS2)
char_u digraphdefault[][3] = /* standard MSDOS digraphs */
{{'C', ',', 128}, /* ~@ (SAS C can't handle the real char) */
{'u', '"', 129}, /* */
{'e', '\'', 130}, /* */
{'a', '^', 131}, /* */
{'a', '"', 132}, /* */
{'a', '`', 133}, /* */
{'a', '@', 134}, /* */
{'c', ',', 135}, /* ~G (SAS C can't handle the real char) */
{'e', '^', 136}, /* ~H (SAS C can't handle the real char) */
{'e', '"', 137}, /* */
{'e', '`', 138}, /* */
{'i', '"', 139}, /* */
{'i', '^', 140}, /* */
{'i', '`', 141}, /* */
{'A', '"', 142}, /* */
{'A', '@', 143}, /* */
{'E', '\'', 144}, /* */
{'a', 'e', 145}, /* */
{'A', 'E', 146}, /* */
{'o', '^', 147}, /* */
{'o', '"', 148}, /* */
{'o', '`', 149}, /* */
{'u', '^', 150}, /* */
{'u', '`', 151}, /* */
{'y', '"', 152}, /* */
{'O', '"', 153}, /* */
{'U', '"', 154}, /* */
{'c', '|', 155}, /* */
{'$', '$', 156}, /* */
{'Y', '-', 157}, /* ~] (SAS C can't handle the real char) */
{'P', 't', 158}, /* */
{'f', 'f', 159}, /* */
{'a', '\'', 160}, /* */
{'i', '\'', 161}, /* ¡ */
{'o', '\'', 162}, /* ¢ */
{'u', '\'', 163}, /* xx (SAS C can't handle the real char) */
{'n', '~', 164}, /* ¤ */
{'N', '~', 165}, /* ¥ */
{'a', 'a', 166}, /* ¦ */
{'o', 'o', 167}, /* § */
{'~', '?', 168}, /* ¨ */
{'-', 'a', 169}, /* © */
{'a', '-', 170}, /* ª */
{'1', '2', 171}, /* « */
{'1', '4', 172}, /* ¬ */
{'~', '!', 173}, /* */
{'<', '<', 174}, /* ® */
{'>', '>', 175}, /* ¯ */
{'s', 's', 225}, /* á */
{'j', 'u', 230}, /* æ */
{'o', '/', 237}, /* í */
{'+', '-', 241}, /* ñ */
{'>', '=', 242}, /* ò */
{'<', '=', 243}, /* ó */
{':', '-', 246}, /* ö */
{'~', '~', 247}, /* ÷ */
{'~', 'o', 248}, /* ø */
{'2', '2', 253}, /* ý */
{NUL, NUL, NUL}
};
#else /* !MSDOS && !WIN32 */
# ifdef MINT
char_u digraphdefault[][3] = /* standard ATARI digraphs */
{{'C', ',', 128}, /* ~@ */
{'u', '"', 129}, /* */
{'e', '\'', 130}, /* */
{'a', '^', 131}, /* */
{'a', '"', 132}, /* */
{'a', '`', 133}, /* */
{'a', '@', 134}, /* */
{'c', ',', 135}, /* ~G */
{'e', '^', 136}, /* ~H */
{'e', '"', 137}, /* */
{'e', '`', 138}, /* */
{'i', '"', 139}, /* */
{'i', '^', 140}, /* */
{'i', '`', 141}, /* */
{'A', '"', 142}, /* */
{'A', '@', 143}, /* */
{'E', '\'', 144}, /* */
{'a', 'e', 145}, /* */
{'A', 'E', 146}, /* */
{'o', '^', 147}, /* */
{'o', '"', 148}, /* */
{'o', '`', 149}, /* */
{'u', '^', 150}, /* */
{'u', '`', 151}, /* */
{'y', '"', 152}, /* */
{'O', '"', 153}, /* */
{'U', '"', 154}, /* */
{'c', '|', 155}, /* */
{'$', '$', 156}, /* */
{'Y', '-', 157}, /* ~] */
{'s', 's', 158}, /* */
{'f', 'f', 159}, /* */
{'a', '\'', 160}, /* */
{'i', '\'', 161}, /* ¡ */
{'o', '\'', 162}, /* ¢ */
{'u', '\'', 163}, /* £ */
{'n', '~', 164}, /* ¤ */
{'N', '~', 165}, /* ¥ */
{'a', 'a', 166}, /* ¦ */
{'o', 'o', 167}, /* § */
{'~', '?', 168}, /* ¨ */
{'-', 'a', 169}, /* © */
{'a', '-', 170}, /* ª */
{'1', '2', 171}, /* « */
{'1', '4', 172}, /* ¬ */
{'~', '!', 173}, /* */
{'<', '<', 174}, /* ® */
{'>', '>', 175}, /* ¯ */
{'j', 'u', 230}, /* æ */
{'o', '/', 237}, /* í */
{'+', '-', 241}, /* ñ */
{'>', '=', 242}, /* ò */
{'<', '=', 243}, /* ó */
{':', '-', 246}, /* ö */
{'~', '~', 247}, /* ÷ */
{'~', 'o', 248}, /* ø */
{'2', '2', 253}, /* ý */
{NUL, NUL, NUL}
};
# else /* !MINT */
# ifdef _INCLUDE_HPUX_SOURCE
char_u digraphdefault[][3] = /* default HPUX digraphs */
{{'A', '`', 161}, /* ¡ */
{'A', '^', 162}, /* ¢ */
{'E', '`', 163}, /* £ */
{'E', '^', 164}, /* ¤ */
{'E', '"', 165}, /* ¥ */
{'I', '^', 166}, /* ¦ */
{'I', '"', 167}, /* § */
{'\'', '\'', 168}, /* ¨ */
{'`', '`', 169}, /* © */
{'^', '^', 170}, /* ª */
{'"', '"', 171}, /* « */
{'~', '~', 172}, /* ¬ */
{'U', '`', 173}, /* */
{'U', '^', 174}, /* ® */
{'L', '=', 175}, /* ¯ */
{'~', '_', 176}, /* ° */
{'Y', '\'', 177}, /* ± */
{'y', '\'', 178}, /* ² */
{'~', 'o', 179}, /* ³ */
{'C', ',', 180}, /* ´ */
{'c', ',', 181}, /* µ */
{'N', '~', 182}, /* ¶ */
{'n', '~', 183}, /* · */
{'~', '!', 184}, /* ¸ */
{'~', '?', 185}, /* ¹ */
{'o', 'x', 186}, /* º */
{'L', '-', 187}, /* » */
{'Y', '=', 188}, /* ¼ */
{'p', 'p', 189}, /* ½ */
{'f', 'l', 190}, /* ¾ */
{'c', '|', 191}, /* ¿ */
{'a', '^', 192}, /* À */
{'e', '^', 193}, /* Á */
{'o', '^', 194}, /* Â */
{'u', '^', 195}, /* Ã */
{'a', '\'', 196}, /* Ä */
{'e', '\'', 197}, /* Å */
{'o', '\'', 198}, /* Æ */
{'u', '\'', 199}, /* Ç */
{'a', '`', 200}, /* È */
{'e', '`', 201}, /* É */
{'o', '`', 202}, /* Ê */
{'u', '`', 203}, /* Ë */
{'a', '"', 204}, /* Ì */
{'e', '"', 205}, /* Í */
{'o', '"', 206}, /* Î */
{'u', '"', 207}, /* Ï */
{'A', 'o', 208}, /* Ð */
{'i', '^', 209}, /* Ñ */
{'O', '/', 210}, /* Ò */
{'A', 'E', 211}, /* Ó */
{'a', 'o', 212}, /* Ô */
{'i', '\'', 213}, /* Õ */
{'o', '/', 214}, /* Ö */
{'a', 'e', 215}, /* × */
{'A', '"', 216}, /* Ø */
{'i', '`', 217}, /* Ù */
{'O', '"', 218}, /* Ú */
{'U', '"', 219}, /* Û */
{'E', '\'', 220}, /* Ü */
{'i', '"', 221}, /* Ý */
{'s', 's', 222}, /* Þ */
{'O', '^', 223}, /* ß */
{'A', '\'', 224}, /* à */
{'A', '~', 225}, /* á */
{'a', '~', 226}, /* â */
{'D', '-', 227}, /* ã */
{'d', '-', 228}, /* ä */
{'I', '\'', 229}, /* å */
{'I', '`', 230}, /* æ */
{'O', '\'', 231}, /* ç */
{'O', '`', 232}, /* è */
{'O', '~', 233}, /* é */
{'o', '~', 234}, /* ê */
{'S', '~', 235}, /* ë */
{'s', '~', 236}, /* ì */
{'U', '\'', 237}, /* í */
{'Y', '"', 238}, /* î */
{'y', '"', 239}, /* ï */
{'p', '-', 240}, /* ð */
{'p', '~', 241}, /* ñ */
{'~', '.', 242}, /* ò */
{'j', 'u', 243}, /* ó */
{'P', 'p', 244}, /* ô */
{'3', '4', 245}, /* õ */
{'-', '-', 246}, /* ö */
{'1', '4', 247}, /* ÷ */
{'1', '2', 248}, /* ø */
{'a', '_', 249}, /* ù */
{'o', '_', 250}, /* ú */
{'<', '<', 251}, /* û */
{'x', 'x', 252}, /* ü */
{'>', '>', 253}, /* ý */
{'+', '-', 254}, /* þ */
{'n', 'u', 255}, /* (char excluded, is EOF on some systems */
{NUL, NUL, NUL}
};
# else /* _INCLUDE_HPUX_SOURCE */
char_u digraphdefault[][3] = /* standard ISO digraphs */
{{'~', '!', 161}, /* ¡ */
{'c', '|', 162}, /* ¢ */
{'$', '$', 163}, /* £ */
{'o', 'x', 164}, /* ¤ */
{'Y', '-', 165}, /* ¥ */
{'|', '|', 166}, /* ¦ */
{'p', 'a', 167}, /* § */
{'"', '"', 168}, /* ¨ */
{'c', 'O', 169}, /* © */
{'a', '-', 170}, /* ª */
{'<', '<', 171}, /* « */
{'-', ',', 172}, /* ¬ */
{'-', '-', 173}, /* */
{'r', 'O', 174}, /* ® */
{'-', '=', 175}, /* ¯ */
{'~', 'o', 176}, /* ° */
{'+', '-', 177}, /* ± */
{'2', '2', 178}, /* ² */
{'3', '3', 179}, /* ³ */
{'\'', '\'', 180}, /* ´ */
{'j', 'u', 181}, /* µ */
{'p', 'p', 182}, /* ¶ */
{'~', '.', 183}, /* · */
{',', ',', 184}, /* ¸ */
{'1', '1', 185}, /* ¹ */
{'o', '-', 186}, /* º */
{'>', '>', 187}, /* » */
{'1', '4', 188}, /* ¼ */
{'1', '2', 189}, /* ½ */
{'3', '4', 190}, /* ¾ */
{'~', '?', 191}, /* ¿ */
{'A', '`', 192}, /* À */
{'A', '\'', 193}, /* Á */
{'A', '^', 194}, /* Â */
{'A', '~', 195}, /* Ã */
{'A', '"', 196}, /* Ä */
{'A', '@', 197}, /* Å */
{'A', 'E', 198}, /* Æ */
{'C', ',', 199}, /* Ç */
{'E', '`', 200}, /* È */
{'E', '\'', 201}, /* É */
{'E', '^', 202}, /* Ê */
{'E', '"', 203}, /* Ë */
{'I', '`', 204}, /* Ì */
{'I', '\'', 205}, /* Í */
{'I', '^', 206}, /* Î */
{'I', '"', 207}, /* Ï */
{'D', '-', 208}, /* Ð */
{'N', '~', 209}, /* Ñ */
{'O', '`', 210}, /* Ò */
{'O', '\'', 211}, /* Ó */
{'O', '^', 212}, /* Ô */
{'O', '~', 213}, /* Õ */
{'O', '"', 214}, /* Ö */
{'/', '\\', 215}, /* × */
{'O', '/', 216}, /* Ø */
{'U', '`', 217}, /* Ù */
{'U', '\'', 218}, /* Ú */
{'U', '^', 219}, /* Û */
{'U', '"', 220}, /* Ü */
{'Y', '\'', 221}, /* Ý */
{'I', 'p', 222}, /* Þ */
{'s', 's', 223}, /* ß */
{'a', '`', 224}, /* à */
{'a', '\'', 225}, /* á */
{'a', '^', 226}, /* â */
{'a', '~', 227}, /* ã */
{'a', '"', 228}, /* ä */
{'a', '@', 229}, /* å */
{'a', 'e', 230}, /* æ */
{'c', ',', 231}, /* ç */
{'e', '`', 232}, /* è */
{'e', '\'', 233}, /* é */
{'e', '^', 234}, /* ê */
{'e', '"', 235}, /* ë */
{'i', '`', 236}, /* ì */
{'i', '\'', 237}, /* í */
{'i', '^', 238}, /* î */
{'i', '"', 239}, /* ï */
{'d', '-', 240}, /* ð */
{'n', '~', 241}, /* ñ */
{'o', '`', 242}, /* ò */
{'o', '\'', 243}, /* ó */
{'o', '^', 244}, /* ô */
{'o', '~', 245}, /* õ */
{'o', '"', 246}, /* ö */
{':', '-', 247}, /* ÷ */
{'o', '/', 248}, /* ø */
{'u', '`', 249}, /* ù */
{'u', '\'', 250}, /* ú */
{'u', '^', 251}, /* û */
{'u', '"', 252}, /* ü */
{'y', '\'', 253}, /* ý */
{'i', 'p', 254}, /* þ */
{'y', '"', 255}, /* (char excluded, is EOF on some systems */
{NUL, NUL, NUL}
};
# endif /* _INCLUDE_HPUX_SOURCE */
# endif /* !MINT */
#endif /* !MSDOS && !WIN32 */
/*
* handle digraphs after typing a character
*/
int
do_digraph(c)
int c;
{
static int backspaced; /* character before K_BS */
static int lastchar; /* last typed character */
if (c == -1) /* init values */
{
backspaced = -1;
}
else if (p_dg)
{
if (backspaced >= 0)
c = getdigraph(backspaced, c, FALSE);
backspaced = -1;
if ((c == K_BS || c == Ctrl('H')) && lastchar >= 0)
backspaced = lastchar;
}
lastchar = c;
return c;
}
/*
* lookup the pair char1, char2 in the digraph tables
* if no match, return char2
*/
static int
getexactdigraph(char1, char2, meta)
int char1;
int char2;
int meta;
{
int i;
int retval;
if (IS_SPECIAL(char1) || IS_SPECIAL(char2))
return char2;
retval = 0;
for (i = 0; ; ++i) /* search added digraphs first */
{
if (i == digraphcount) /* end of added table, search defaults */
{
for (i = 0; digraphdefault[i][0] != 0; ++i)
if (digraphdefault[i][0] == char1 && digraphdefault[i][1] == char2)
{
retval = digraphdefault[i][2];
break;
}
break;
}
if (digraphnew[i][0] == char1 && digraphnew[i][1] == char2)
{
retval = digraphnew[i][2];
break;
}
}
if (retval == 0) /* digraph deleted or not found */
{
if (char1 == ' ' && meta) /* <space> <char> --> meta-char */
return (char2 | 0x80);
return char2;
}
return retval;
}
/*
* Get digraph.
* Allow for both char1-char2 and char2-char1
*/
int
getdigraph(char1, char2, meta)
int char1;
int char2;
int meta;
{
int retval;
if (((retval = getexactdigraph(char1, char2, meta)) == char2) &&
(char1 != char2) &&
((retval = getexactdigraph(char2, char1, meta)) == char1))
return char2;
return retval;
}
/*
* put the digraphs in the argument string in the digraph table
* format: {c1}{c2} char {c1}{c2} char ...
*/
void
putdigraph(str)
char_u *str;
{
int char1, char2, n;
char_u (*newtab)[3];
int i;
while (*str)
{
str = skipwhite(str);
if ((char1 = *str++) == 0 || (char2 = *str++) == 0)
return;
if (char1 == ESC || char2 == ESC)
{
EMSG("Escape not allowed in digraph");
return;
}
str = skipwhite(str);
if (!isdigit(*str))
{
emsg(e_number);
return;
}
n = getdigits(&str);
if (digraphnew) /* search the table for existing entry */
{
for (i = 0; i < digraphcount; ++i)
if (digraphnew[i][0] == char1 && digraphnew[i][1] == char2)
{
digraphnew[i][2] = n;
break;
}
if (i < digraphcount)
continue;
}
newtab = (char_u (*)[3])alloc(digraphcount * 3 + 3);
if (newtab)
{
vim_memmove((char *)newtab, (char *)digraphnew,
(size_t)(digraphcount * 3));
vim_free(digraphnew);
digraphnew = newtab;
digraphnew[digraphcount][0] = char1;
digraphnew[digraphcount][1] = char2;
digraphnew[digraphcount][2] = n;
++digraphcount;
}
}
}
void
listdigraphs()
{
int i;
msg_outchar('\n');
printdigraph(NULL);
for (i = 0; digraphdefault[i][0] && !got_int; ++i)
{
if (getexactdigraph(digraphdefault[i][0], digraphdefault[i][1],
FALSE) == digraphdefault[i][2])
printdigraph(digraphdefault[i]);
mch_breakcheck();
}
for (i = 0; i < digraphcount && !got_int; ++i)
{
printdigraph(digraphnew[i]);
mch_breakcheck();
}
must_redraw = CLEAR; /* clear screen, because some digraphs may be wrong,
* in which case we messed up NextScreen */
}
static void
printdigraph(p)
char_u *p;
{
char_u buf[9];
static int len;
if (p == NULL)
len = 0;
else if (p[2] != 0)
{
if (len > Columns - 11)
{
msg_outchar('\n');
len = 0;
}
if (len)
MSG_OUTSTR(" ");
sprintf((char *)buf, "%c%c %c %3d", p[0], p[1], p[2], p[2]);
msg_outstr(buf);
len += 11;
}
}
#endif /* DIGRAPHS */